import sys
import re
import pyperclip

# while 1:
#     data = []
#     for line in sys.stdin:
#         if line != "\n":#停止条件
#             data.append(line)
#         else:
#             break
#     # print(data)
#     for i,d in enumerate(data):
#         if i==0:
#             matchObj=re.match("(.*) .h (.*$)",d)
#             print(f"  /// \\brief <b> {matchObj.group(2)} ({matchObj.group(1)}) </b>\n"
#                   f"  /// \details")
#         else:
#             matchObj=re.match("(^.*$)",d)
#             print(f"  /// {matchObj.group()} \\n")


print("ENTER to Processing Clipboard Data, Q + ENTER to quit")
for line in sys.stdin:
    
    if line == "\n":#运行条件
        data=pyperclip.paste()
        data=data.splitlines()
        if(data==[]):
            print("No Clipboard Data")
        output=""
        for i,d in enumerate(data):
            if i==0:
                matchObj=re.match("(.*) .h (.*$)",d)
                if (matchObj==None):
                    print("Clipboard Data Error")
                    break
                output+=f"\n  /// \\brief <b> {matchObj.group(2)} ({matchObj.group(1)}) </b>\n  /// \details\n"
            else:
                matchObj=re.match("(^.*$)",d)
                output+=f"  /// \\b {matchObj.group()} \\n\n"
        print(output)
        output=output[:-1]
        pyperclip.copy(output)
        print("ENTER to Processing Clipboard Data, Q + ENTER to quit")
    if line == "q\n" or line ==  "Q\n":
        exit()

# data form is like:
#R 0h Device Fault Status
#0h = No fault condition is detected
#1h = Fault condition is detected